package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 发送消费验证码请求参数类
 *
 * @author lijian
 * @version 2014年7月10日 - 上午9:35:18
 */
public class SmsSendConsumeCodeRequest extends Request {

	private String phone;
	
	private Integer userId;
	
	private String ip;
	
	private Integer applicablePlatformId;
	
	public SmsSendConsumeCodeRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.applicablePlatformId.getParamName(), ApplicablePlatformEnum.WEB.getId());
		if (!StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("请输入正确的手机号");
		}
		if (userId < 1) {
			throw new RequestIllegalException("userId error " + userId);
		}
		if ("127.0.0.1".equals(ip)) {
			this.ip = requestInfo.getUserIp();
		}
		if (StringUtil.isEmpty(ip)) {
			throw new RequestIllegalException("ip不能为空");
		}
	}
	
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Integer getApplicablePlatformId() {
		return applicablePlatformId;
	}

	public void setApplicablePlatformId(Integer applicablePlatformId) {
		this.applicablePlatformId = applicablePlatformId;
	}

}
